//
//  HLTzhuceTableViewController.m
//  huiliantong
//
//  Created by hlt on 15/8/28.
//  Copyright (c) 2015年 hlt. All rights reserved.
//

#import "HLTzhuceTableViewController.h"
#import "HLTuserchargeViewController.h"
//#import "HLTzhuceTableViewCell.h"
@interface HLTzhuceTableViewController ()

@end

@implementation HLTzhuceTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置返回的按钮的字体的颜色的
    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    //设置导航的背景颜色的
    self.navigationController.navigationBar.barTintColor = navigationBarColor;
    
    
    //    self.navigationController.title=@"登陆";
    [self.navigationItem setTitle:@"注册"];

     [self creatcs];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}







- (IBAction)userxieyi:(id)sender {
    
    ////调用网页版用户协议
    NSString *url=[NSString stringWithFormat:@"http://www.hltgz.com/wx/mobile/index.php?m=default&c=article&a=infoapp&aid=54"];
    
    
    
    
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    HLTuserchargeViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"HLTuserchargeViewController"];
    
    vc.hidesBottomBarWhenPushed = YES;
    vc.url=url;
    [vc setTitle:@"用户协议"];
    
    //            HLTCustomerserviceTableViewController *vc =[[HLTCustomerserviceTableViewController alloc]init];
    [self.navigationController pushViewController:vc animated:NO];
    
}








- (void)btnAction:(id)sender {
    NSLog(@"click");
    
    NSString *url=[zhucefasong stringByAppendingFormat:@"&mobile=%@",self.username.text];
    [HLTNetWorkingtool getdic:url success:^(NSDictionary *ary) {
        
        
//        NSString *str=ary[@"code"];
        
        //18786797729
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString *str = [numberFormatter stringFromNumber:ary[@"code"]];
        if ([str isEqual:@"2"]) {
            
            
            self.pwd=ary[@"mobile_code"];
            
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"短信发送成功" message:ary[@"msg"] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil];
            
            [alert show];
            
            
            
        }
        else{
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"短信发送失败" message:ary[@"msg"] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil];
            
            [alert show];
            
            
            
        }
    } faliure:^(NSString *error) {
        
        
    }
     ];
    
    JxbScaleButton* btn = (JxbScaleButton*)sender;
    JxbScaleSetting* setting = [[JxbScaleSetting alloc] init];
    setting.strPrefix = @"";
    setting.strSuffix = @"秒";
    setting.strCommon = @"重新发送";
    setting.indexStart = 60;
    [btn startWithSetting:setting];
}

- (void)creatcs {
    
    
    JxbScaleButton* btn = [[JxbScaleButton alloc] initWithFrame:CGRectMake(0, 0, self.fasongview.frame.size.width, self.fasongview.frame.size.height)];
    btn.layer.cornerRadius = 5;
    btn.layer.masksToBounds = YES;
    btn.titleLabel.font=[UIFont systemFontOfSize: 14.0];
    [btn setTitle: @"获取验证码" forState: UIControlStateNormal];
    btn.backgroundColor=navigationBarColor;
    [self.fasongview addSubview:btn];
    
    //    [self btnAction:btn];
    
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}



- (IBAction)zuche:(id)sender {
    
    
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    
    
    
    
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"注册时验证码就是登录密码" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil];
    
    [alert show];
    
    
    if ([self.pwd isEqual:self.yanzhengma.text]) {
        
        
        UIView *view1=[[UIView alloc] initWithFrame:self.view.bounds];
        view1.backgroundColor=[UIColor grayColor];
        view1.alpha=0.4;
        [self.view addSubview:view1];
        MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
        indicatorView.delegate = self;
        indicatorView.numberOfCircles = 3;
        indicatorView.radius = 20;
        indicatorView.internalSpacing = 3;
        indicatorView.center = self.view.center;
        [indicatorView startAnimating];
        [self.view addSubview:indicatorView];
        
        
        //base64 编码
        NSString *base64pwd= [SetBase64andMd5 base64:self.yanzhengma.text ncryptOrDecrypt:kCCEncrypt];
        
        NSString *url=[zhuce1 stringByAppendingFormat:@"&username=%@&password=%@",self.username.text,base64pwd];
        [HLTNetWorkingtool getary:url success:^(NSArray *ary) {
            
            if ([ary[0][@"status"] isEqual:@"0"]) {
                //成功
                [self.navigationController popViewControllerAnimated:YES];
                [indicatorView stopAnimating];
                [view1 removeFromSuperview];
            }else
            {
                UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"注册失败" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil];
                
                [alert show];
                [indicatorView stopAnimating];
                [view1 removeFromSuperview];
            }
        } faliure:^(NSString *error) {
            [indicatorView stopAnimating];
            [view1 removeFromSuperview];
        }];
        
        
        
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"验证码不正确" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"好", nil];
        
        [alert show];
        
    }
    
    
    
    
    
    
}





- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    
}




#pragma mark - MONActivityIndicatorViewDelegate Methods
- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView
      circleBackgroundColorAtIndex:(NSUInteger)index {
    CGFloat red   = (arc4random() % 256)/255.0;
    CGFloat green = (arc4random() % 256)/255.0;
    CGFloat blue  = (arc4random() % 256)/255.0;
    CGFloat alpha = 1.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}



@end
